package com.codingday.app;

import java.util.ArrayList;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class TODONowInside extends LinearLayout {

		int position;
		Context context;
		TextView tv_TODO_Title;
		TextView tv_TODO_Desc;
		Button bt_TODO_Detail;
		Button bt_TODO_Later;
		Button bt_TODO_Complete;
		
		TODO todo;
		
		public TODONowInside(Context context) {
			super(context);
			this.context = context;
			initView2();

		}
		public TODONowInside(Context context, AttributeSet attrs){
			super(context, attrs);
			this.context = context;
			initView2();
		}
		
		public void initView2(){
			   LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			   View view=layoutInflater.inflate(R.layout.todo_now_inside_view,this);
			   
			   tv_TODO_Title = (TextView)findViewById(R.id.todo_now_inside_title);
			   tv_TODO_Desc = (TextView)findViewById(R.id.todo_now_inside_desc);
			   
			   initButtons();
		}
		
		public void initButtons(){
			   bt_TODO_Later = (Button)findViewById(R.id.todo_now_inside_later);
			   bt_TODO_Complete = (Button)findViewById(R.id.todo_now_inside_completed);
			   bt_TODO_Detail = (Button)findViewById(R.id.todo_now_inside_view_todo);
			   
			   bt_TODO_Detail.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					Intent intent = new Intent(context, TODOView.class);
					intent.putExtra("TODOID", todo.getID());
					context.startActivity(intent);	
				}
				   
			   });
			   
			   bt_TODO_Later.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					//((Activity) context).finish();
					// Do Nothing
					bt_TODO_Complete.setEnabled(false);
					bt_TODO_Later.setEnabled(false);
				}
				   
			   });
			   
			   
			   bt_TODO_Complete.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					completeTODO();
					bt_TODO_Complete.setEnabled(false);
					bt_TODO_Later.setEnabled(false);
					Log.i("","");
				}
				   
			   });
		}
		
		public void completeTODO(){
			todo.setCompleted(true);
			SaveManager.FinishTODO(todo);
			Log.i("TODONowInside","Completed");

		}
		
		/*
		public void initView(){
			this.setOrientation(VERTICAL);
			tv_TODO_Title = new TextView(context);
			tv_TODO_Title.setText("Hello");
			addView(tv_TODO_Title);
			

			
			tv_TODO_Desc = new TextView(context);
			tv_TODO_Desc.setText("KEKEKE");
			addView(tv_TODO_Desc);

			bt_TODO_Detail = new Button(context);
			bt_TODO_Detail.setText("Detail");
			bt_TODO_Detail.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					Toast.makeText(context, "See Detail Info", 1).show();
					((TODONowList)context).goToViewToDoActivity(position);
				}
				
			});
			addView(bt_TODO_Detail);
			
		}
		*/
		
		public void setTODO(int id){
			//this.position = position;
			ArrayList<TODO> todolist = TODOListManager.getTODOList();
			todo = null;
			position = -1;
			for(int i = 0; i < todolist.size() ; i++){
				TODO tempTodo = todolist.get(i);
				if(tempTodo.getID() == id){
					todo = tempTodo;
					position = i;
					break;
				}
			}
			if(todo == null){
				Log.i("TODONowInside","Error! Failed To fetch TODO for ID:"+id);
				return;
			}
			
			tv_TODO_Title.setText(todo.getTitle());
			tv_TODO_Desc.setText(todo.getDesc());
		}


}
